﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_ImageCrop : System.Web.UI.Page
{
    
    Int32 iWorkID,iPlaceID;

    protected void Page_Load(object sender, EventArgs e)
    {
        
        GetParametrs();
        lnkBack.NavigateUrl = string.Format("addWork.aspx?id={0}", iWorkID);
    }

    private void GetParametrs()
    {
        iWorkID = Convert.ToInt32(Request.QueryString["Work"]);
        iPlaceID = Convert.ToInt32(Request.QueryString["Place"]);
    }

    protected void btnCrop_Click(object sender, EventArgs e)
    {

        /* thats the method to crop and save the image.*/
         string sImgName=ViewState["File"].ToString();
        wci1.Crop(LocalFunctions.sMappedPath+"\\prv_" +sImgName);

        /*
         this part is just to show the image after its been cropped and saved! so focus on just the code above.
         */
        Image img = new Image();
        img.ImageUrl = "~/content/galery/prv_" + sImgName + "?rnd=" + (new Random()).Next();  // added random for caching issue.
        this.Controls.Add(img);

        // test comment for patch by @cemsisman @20090520

        //save both images
        Dal.arParams.Clear();
        Dal.arParams.Add(iWorkID);
        Dal.arParams.Add(sImgName);
        Dal.arParams.Add(iPlaceID);
        Dal.arParams.Add("prv_" + sImgName);
        Dal.ExecuteDBsp("Admin_UploadImage", Dal.arParams);
    }



    protected void btnUplImage_Click(object sender, EventArgs e)
    {
        if (uplImage.HasFile)
        {
            string sExt = System.IO.Path.GetExtension(uplImage.PostedFile.FileName);
            string sFileName =  Helper.GenerateUniqueFileName()  + sExt;
            uplImage.SaveAs(LocalFunctions.sMappedPath + "\\" + sFileName);

            ViewState["File"] = sFileName;
            Image1.ImageUrl = "~/content/galery/" + sFileName;
        }
    }
}